﻿module Sustainalytics.ControversyAlert.Security {

    import Routing = Sustainalytics.Routing;

    export class ControversyAlertRouteSecurityService implements Routing.IRouteSecurityService {

        constructor(
            private $q: ng.IQService,
            private ControversyAlertPermissionsService: ControversyAlertPermissionsService) {
        }

        validate(security: Routing.RouteSecurity): ng.IPromise<boolean> {
            var ctx = this;

            var valid = ctx.ControversyAlertPermissionsService.hasControversyAlert();

            return ctx.$q.when(valid);
        }
    }

    export var caRouteSecurityServiceName = 'ControversyAlertRouteSecurityService';

    angular.module(caSecurityModuleName).service(caRouteSecurityServiceName,
        ['$q', 'ControversyAlertPermissionsService', ControversyAlertRouteSecurityService]);
}